package org.codefinger.dao;

import java.util.Map;

import org.codefinger.dao.impl.DataAccesser;
import org.codefinger.dao.impl.TableInfo;

public class DeleteFrom implements Deleter {

	private DataAccesser	dataAccesser;

	private TableInfo		tableInfo;

	public DeleteFrom(DataAccesser dataAccesser, String table) {
		super();
		this.dataAccesser = dataAccesser;
		this.tableInfo = dataAccesser.getTableInfo(table.toUpperCase());
	}

	public DeleteWhere where(String condition) {
		return new DeleteWhere(dataAccesser, tableInfo, condition);
	}

	@Override
	public int execute(Object... params) {
		return dataAccesser.deleteAll(tableInfo);
	}
	
	@Override
	public int execute(Map<String, Object> params) {
		return dataAccesser.deleteAll(tableInfo);
	}

	@Override
	public DeleterChain putParam(String name, Object value) {
		return new DeleterChain() {

			@Override
			public DeleterChain putParam(String name, Object value) {
				return this;
			}

			@Override
			public int execute() {
				return dataAccesser.deleteAll(tableInfo);
			}

		};
	}

}